<template>
  <div class="home-singer">
    <div class="title">
      <h1>新歌速递</h1>
      <div class="genduo-content">
        <div class="gengduo">
          <img src="../../assets/index-play1.png" alt="" />
          <span>播放</span>
        </div>
      </div>
    </div>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="singerandpic">
            <div class="pic">
              <van-image :src="item.album.picUrl" radius="10px" />
            </div>
            <div class="singer">
              <!-- 歌曲名字 -->
              <span>{{ item.name }}</span>
              <span>-</span>
              <!-- 歌手名字 -->
              <span v-for="(artists, index) in item.artists" :key="artists.id">
                {{ artists.name }}
                <span v-show="index != item.artists.length - 1"></span>
              </span>
              <div class="singer-company">
                <span>{{ item.album.company }}</span>
              </div>
            </div>
            <div class="play">
              <img src="../../assets/index-play.png" alt="" />
            </div>
          </div>
        </li>
      </ul>
      <!-- </van-list> -->
    </div>
  </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js"; //引入betterscroll

export default {
  data() {
    return {
      // list: [],
      listData: [],
      // loading: false,
      // finished: false,
    };
  },
  created() {
    this.getSingerListData();
  },
  methods: {
    getSingerListData() {
      this.$request("get", "/top/song").then((res) => {
        // console.log(res);
        if (res.code == 200) {
          this.listData = this.listData.concat(res.data);
          // console.log(this.listData);
        }
        // 异步数据的处理
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        ); //调用横向滚动的方法
      });
    },
    onLoad() {
      setTimeout(() => {
        console.log(this.list);
      }, 50);
    },
    selectItem(item) {
      const id = item.singer_mid;
      this.$router.push({
        path: `/singerhome/${id}`,
      });
    },
  },
};
</script>
<style scoped>
.home-singer {
  margin-top: 12px;
}
.title {
  align-items: center;
  display: flex;
  /* background: aquamarine; */
}
.title > h1 {
  width: 25%;
  margin-left: 20px;
  text-align: left;
  font-size: 22px;
}
.genduo-content {
  display: flex;
  width: 50%;
  background: chartreuse;
  align-items: center;
}
.gengduo {
  display: flex;
  right: 23px;
  position: absolute;
  align-items: center;
  border: 1px solid rgb(75, 74, 74);
  border-radius: 15px;
  width: 70px;
  justify-content: center;
}
.gengduo > img {
  width: 20%;
}
.gengduo > span {
  padding-left: 1.5px;
  padding-right: 1.5px;
  padding-top: 4px;
  padding-bottom: 4px;
  font-size: 16px;
  color: black;
}
.play > img {
  width: 14%;
  /* margin-right: 100px; */
}
.play {
  position: absolute;
  text-align: right;
  right: 50px;
  /* background: lightcoral; */
}
.singer-company {
  padding-top: 25px;
  text-align: left;
  font-size: 13px;
}

.singerandpic {
  position: relative;
  align-items: center;
  display: flex;
}
.singer {
  /* margin-left: 40px; */
  margin-left: 30px;
  text-align: left;
}
.singer > span {
  word-break: keep-all;
  white-space: nowrap; /* *文字不换行 */
  width: fit-content; /*宽度自适应*/
  font-size: 17px;
}
.singer > span:nth-child(4) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(5) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(6) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(9) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(5) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(7) {
  color: rgb(146, 149, 151);
  font-size: 13px;
}
.singer > span:nth-child(8) {
  color: rgb(146, 149, 151);
  font-size: 10px;
}
.singer > span:nth-child(3) {
  color: rgb(146, 149, 151);
  font-size: 10px;
}
.pic {
  width: 17%;
}
.wrapper {
  width: 100%; /** 容器的宽度就是屏幕的宽度 */
  overflow: hidden;
}
ul.content li {
  display: inline-block; /**行内元素*/
  /* width: 15rem; */
  /* li默认使用块级元素 */
  /* display: inline-block; */
  /**行内元素*/
  width: 31rem;
  /* background: bisque; */
  vertical-align: top; /**垂直方向的algin顶满上一个div */
}
ul.content li * {
  /**选取下面的所有元素*/
  margin: 0.1rem;
}
ul.content li > span {
  color: rgb(41, 31, 24);
}
.home-singer > h1 {
  margin-left: 20px;
  text-align: left;
  font-size: 22px;
}
</style>